﻿/*
* PinyinToMakabaka.cpp
* 将拼音、英语、数字转为马卡巴卡语
* 版权所有(c)，马卡巴卡语语言研究组，保留所有权利
*/

#include "PinyinToMakabaka.h"
#include "UI.h"

wstring PinyinToMakabaka(wstring in)
{
	wstring out;
	while (!in.empty())
	{
		wstring s1;
		if (in.find(L' ') != in.npos)
		{
			s1 = in.substr(0, in.find(L' '));
			in.erase(0, in.find(L' ') + 1);
		}
		else
		{
			s1 = in;
			in.clear();
		}
		wstring rs;
		bool VtoU = false;

		if (s1 == L"ng")
		{
			out += L"bi";
			continue;
		}
		if (s1 == L"m")
		{
			out += L"gi";
			continue;
		}

		if (s1 == L"yo")
		{
			out += L"wami";
			continue;
		}

		if (s1[1] == L'h')
		{
			switch (s1[0])
			{
			case L'z':
				rs = L"bu";
				break;
			case L'c':
				rs = L"du";
				break;
			case L's':
				rs = L"gu";
				break;
			default:
				break;
			}
			s1.erase(0, 2);
		}
		else
		{
			switch (s1[0])
			{
			case L'b':
				rs = L"da";
				break;
			case L'c':
				rs = L"ga";
				break;
			case L'd':
				rs = L"ka";
				break;
			case L'f':
				rs = L"ra";
				break;
			case L'g':
				rs = L"sa";
				break;
			case L'h':
				rs = L"ta";
				break;
			case L'j':
				VtoU = true;
				rs = L"ya";
				break;
			case L'k':
				rs = L"bi";
				break;
			case L'l':
				rs = L"di";
				break;
			case L'm':
				rs = L"gi";
				break;
			case L'n':
				rs = L"ki";
				break;
			case L'p':
				rs = L"ri";
				break;
			case L'q':
				VtoU = true;
				rs = L"si";
				break;
			case L'r':
				rs = L"ti";
				break;
			case L's':
				rs = L"wi";
				break;
			case L't':
				rs = L"yi";
				break;
			case L'x':
				VtoU = true;
				rs = L"ku";
				break;
			case L'z':
				rs = L"ru";
				break;
			default:
				rs = L"su";
				break;
			}
			if (rs != L"su")
				s1.erase(0, 1);
			else
				rs.clear();
		}
		
		bool f = false;

		if (s1 == L"a")			f = true, rs += L"ba";
		if (s1 == L"ai")		f = true, rs += L"da";
		if (s1 == L"ei")		f = true, rs += L"ga";
		if (s1 == L"ao")		f = true, rs += L"ka";
		if (s1 == L"e")			f = true, rs += L"ma";
		if (s1 == L"ou")		f = true, rs += L"ra";
		if (s1 == L"an")		f = true, rs += L"sa";
		if (s1 == L"en")		f = true, rs += L"ta";

		if (s1 == L"i")			f = true, rs += L"wa";
		if (s1 == L"yi")		f = true, rs += L"wa";

		if (s1 == L"ang")		f = true, rs += L"ya";
		if (s1 == L"eng")		f = true, rs += L"bi";
		if (s1 == L"ong")		f = true, rs += L"di";
		if (s1 == L"ia")		f = true, rs += L"gi";
		if (s1 == L"ie")		f = true, rs += L"ki";

		if (s1 == L"ya")		f = true, rs += L"gi";
		if (s1 == L"ye")		f = true, rs += L"ki";

		if (s1 == L"o")			f = true, rs += L"mi";
		if (s1 == L"iao")		f = true, rs += L"ri";
		if (s1 == L"iu")		f = true, rs += L"si";
		if (s1 == L"ian")		f = true, rs += L"ti";
		if (s1 == L"in")		f = true, rs += L"wi";
		if (s1 == L"iang")		f = true, rs += L"yi";

		if (s1 == L"yao")		f = true, rs += L"ri";
		if (s1 == L"you")		f = true, rs += L"si";
		if (s1 == L"yan")		f = true, rs += L"ti";
		if (s1 == L"yin")		f = true, rs += L"wi";
		if (s1 == L"yang")		f = true, rs += L"yi";


		if (s1 == L"u")			if (!VtoU)f = true, rs += L"bu"; else f = true, rs += L"du";
		if (s1 == L"wu")		f = true, rs += L"bu";

		if (s1 == L"v")			f = true, rs += L"du";
		if (s1 == L"yu")		f = true, rs += L"du";

		if (s1 == L"ing")		f = true, rs += L"gu";
		if (s1 == L"iong")		f = true, rs += L"ku";
		if (s1 == L"ying")		f = true, rs += L"gu";
		if (s1 == L"yong")		f = true, rs += L"ku";



		if (s1 == L"ua")		f = true, rs += L"mu";
		if (s1 == L"uo")		f = true, rs += L"ru";
		if (s1 == L"uai")		f = true, rs += L"bum";
		if (s1 == L"ui")		f = true, rs += L"dum";
		if (s1 == L"uan")		if (!VtoU)f = true, rs += L"gum"; else f = true, rs += L"tum";
		if (s1 == L"uen")		f = true, rs += L"kum";
		if (s1 == L"uang")		f = true, rs += L"mum";
		if (s1 == L"ueng")		f = true, rs += L"rum";

		if (s1 == L"wa")		f = true, rs += L"mu";
		if (s1 == L"wo")		f = true, rs += L"ru";
		if (s1 == L"wai")		f = true, rs += L"bum";
		if (s1 == L"wei")		f = true, rs += L"dum";
		if (s1 == L"wan")		f = true, rs += L"gum";
		if (s1 == L"wen")		f = true, rs += L"kum";
		if (s1 == L"wang")		f = true, rs += L"mum";
		if (s1 == L"weng")		f = true, rs += L"rum";


		if (s1 == L"ve")		f = true, rs += L"sum";
		if (s1 == L"ue")		f = true, rs += L"sum";
		if (s1 == L"van")		f = true, rs += L"tum";
		if (s1 == L"vn")		f = true, rs += L"wum";
		if (s1 == L"un")		if (!VtoU)f = true, rs += L"kum";else f = true, rs += L"wum";

		if (s1 == L"yue")		f = true, rs += L"sum";
		if (s1 == L"yuan")		f = true, rs += L"tum";
		if (s1 == L"yun")		f = true, rs += L"wum";

		if (s1 == L"er")		f = true, rs += L"yum";


		if (f == false)
		{
			SetOutputColor(4);
			wcout << endl << endl;
			wcout << L"致命错误：发现非法拼音。翻译结果无效。" << endl;
			wcout << L"程序无法继续运行。请关闭窗口。" << endl;
			SetOutputColor();
			abort();
		}


		out += rs;
	}

	return out;
}


wstring EnglishToMakabaka(wstring s)
{
	wstring rs;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] >= L'A' && s[i] <= L'Z')
			s[i] = s[i] - L'A' + L'a';
		switch (s[i])
		{
		case L'a':
			rs += L"ba";
			break;
		case L'b':
			rs += L"da";
			break;
		case L'c':
			rs += L"ga";
			break;
		case L'd':
			rs += L"ka";
			break;
		case L'e':
			rs += L"ma";
			break;
		case L'f':
			rs += L"ra";
			break;
		case L'g':
			rs += L"sa";
			break;
		case L'h':
			rs += L"ta";
			break;
		case L'i':
			rs += L"wa";
			break;
		case L'j':
			rs += L"ya";
			break;
		case L'k':
			rs += L"bi";
			break;
		case L'l':
			rs += L"di";
			break;
		case L'm':
			rs += L"gi";
			break;
		case L'n':
			rs += L"ki";
			break;
		case L'o':
			rs += L"mi";
			break;
		case L'p':
			rs += L"ri";
			break;
		case L'q':
			rs += L"si";
			break;
		case L'r':
			rs += L"ti";
			break;
		case L's':
			rs += L"wi";
			break;
		case L't':
			rs += L"yi";
			break;
		case L'u':
			rs += L"bu";
			break;
		case L'v':
			rs += L"du";
			break;
		case L'w':
			rs += L"gu";
			break;
		case L'x':
			rs += L"ku";
			break;
		case L'y':
			rs += L"mu";
			break;
		case L'z':
			rs += L"ru";
			break;
		case L'0':
			rs += L"bum";
			break;
		case L'1':
			rs += L"dum";
			break;
		case L'2':
			rs += L"gum";
			break;
		case L'3':
			rs += L"kum";
			break;
		case L'4':
			rs += L"mum";
			break;
		case L'5':
			rs += L"rum";
			break;
		case L'6':
			rs += L"sum";
			break;
		case L'7':
			rs += L"tum";
			break;
		case L'8':
			rs += L"wum";
			break;
		case L'9':
			rs += L"yum";
			break;
		default:
			rs += s[i];
			break;
		}
	}
	return rs;
}